import React, { lazy } from "react"
import { createBrowserRouter, Navigate } from "react-router-dom"

const ErrorTracking = lazy(() => import(/* webpackChunkName:"ErrorTracking" */ "@/views/ErrorTracking"))
const PerformanceTracking = lazy(() => import(/* webpackChunkName:"PerformanceTracking" */ "@/views/PerformanceTracking"))
const BehaviorTracking = lazy(() => import(/* webpackChunkName:"BehaviorTracking" */ "@/views/BehaviorTracking"))
const Home = lazy(() => import(/* webpackChunkName:"Home" */ "@/views/Home"))
const NotFound = lazy(() => import(/* webpackChunkName:"NotFound" */ "@/views/NotFound"))
const WhiteScreenTracking = lazy(() => import(/* webpackChunkName:"WhiteScreenTracking" */ "@/views/BlankScreenTracking"))
const ErrorBoundary = lazy(() => import(/* webpackChunkName:"ErrorBoundary" */ "@/ErrorBoundary"))

const router = createBrowserRouter([
    {
        path: "/",
        element: <Navigate to="/home" />
    },
    {
        path: "/home",
        element: <Home />,
        children: [
            {
                path: "/home",
                element: <Navigate to="/home/performance" />
            },
            {
                path: "/home/performance",
                element: <PerformanceTracking />
            },
            {
                path: "/home/error",
                element: <ErrorTracking />
            },
            {
                path: "/home/behavior",
                element: (
                    <ErrorBoundary
                        fallback={
                            <div>
                                <h1>哎呀，出错了！</h1>
                                <p>抱歉，我们遇到了一些问题</p>
                            </div>
                        }
                    >
                        <BehaviorTracking />
                    </ErrorBoundary>
                )
            },
            {
                path: "/home/white",
                element: <WhiteScreenTracking />
            }
        ]
    },
    {
        path: "*",
        element: <NotFound />
    }
])

export default router

export const HOME_PATHNAME = "/"
